import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Top extends ClothingItem {
    String sleeves;
    String length;
    String neckline;

    boolean hasButtons;
    boolean needsBottom;
    boolean needsMatch;

    ArrayList<Integer> topMatchIds;
    ArrayList<Integer> bottomMatchIds;

    Top() {

    }

    Top(String fileName) throws IOException {
        BufferedReader input = new BufferedReader(new FileReader(fileName));
        super.idNumber = Integer.parseInt(input.readLine());
        super.brand = input.readLine();
        super.color = input.readLine();
        super.size = input.readLine();
        super.material = input.readLine();
        super.shortType = input.readLine();
        super.shortColor = input.readLine();
        super.minimumTemperature = Integer.parseInt(input.readLine());
        super.wears = Integer.parseInt(input.readLine());
        super.formality = Integer.parseInt(input.readLine());
        this.sleeves = input.readLine();
        this.length = input.readLine();
        this.neckline = input.readLine();
        this.hasButtons = Boolean.parseBoolean(input.readLine());
        this.needsBottom = Boolean.parseBoolean(input.readLine());
        this.needsMatch = Boolean.parseBoolean(input.readLine());

        List<String> topMatchIdsAsStrings = new ArrayList<String>(
                Arrays.asList((input.readLine()).split(",")));
        this.topMatchIds = new ArrayList<Integer>();
        for (String string : topMatchIdsAsStrings) {
            this.topMatchIds.add(Integer.valueOf(string));
        }

        /*
         * List<String> bottomMatchIdsAsStrings = new ArrayList<String>(
         * Arrays.asList((input.readLine()).split(","))); this.bottomMatchIds =
         * new ArrayList<Integer>(); for (String string :
         * bottomMatchIdsAsStrings) {
         * this.bottomMatchIds.add(Integer.valueOf(string)); }
         */

        input.close();
    }

    Top(int idNumber, String brand, String color, String size, String material,
            String shortType, String shortColor, int minimumTemperature,
            int wears, int formality, String sleeves, String length,
            String neckline, boolean hasButtons, boolean needsBottom,
            boolean needsMatch) {
        super.idNumber = idNumber;
        super.brand = brand;
        super.color = color;
        super.size = size;
        super.material = material;
        super.shortType = shortType;
        super.shortColor = shortColor;
        super.minimumTemperature = minimumTemperature;
        super.wears = wears;
        super.formality = formality;
        this.sleeves = sleeves;
        this.length = length;
        this.neckline = neckline;
        this.hasButtons = hasButtons;
        this.needsBottom = needsBottom;
        this.needsMatch = needsMatch;
    }

    Top(BufferedReader consoleIn, int idNumber) throws NumberFormatException,
            IOException {
        super.idNumber = idNumber;
        System.out.println("Enter brand: ");
        super.brand = consoleIn.readLine();
        System.out.println("Enter color: ");
        super.color = consoleIn.readLine();
        System.out.println("Enter size: ");
        super.size = consoleIn.readLine();
        System.out.println("Enter material: ");
        super.material = consoleIn.readLine();
        System.out.println("Enter short type: ");
        super.shortType = consoleIn.readLine();
        System.out.println("Enter short color: ");
        super.shortColor = consoleIn.readLine();
        System.out.println("Enter minimum temperature: ");
        super.minimumTemperature = Integer.parseInt(consoleIn.readLine());
        this.wears = 0;
        System.out.println("Enter formality: ");
        super.formality = Integer.parseInt(consoleIn.readLine());
        System.out.println("Enter sleeves: ");
        this.sleeves = consoleIn.readLine();
        System.out.println("Enter length: ");
        this.length = consoleIn.readLine();
        System.out.println("Enter neckline: ");
        this.neckline = consoleIn.readLine();
        System.out.println("Enter if it has buttons (true/false): ");
        this.hasButtons = Boolean.parseBoolean(consoleIn.readLine());
        System.out.println("Enter if it needs a bottom (true/false): ");
        this.needsBottom = Boolean.parseBoolean(consoleIn.readLine());
        System.out.println("Enter if it needs a match (true/false): ");
        this.needsMatch = Boolean.parseBoolean(consoleIn.readLine());

        System.out.println("Enter matching top IDs, separated by a comma: ");
        List<String> topMatchIdsAsStrings = new ArrayList<String>(
                Arrays.asList((consoleIn.readLine()).split(",")));
        this.topMatchIds = new ArrayList<Integer>();
        for (String string : topMatchIdsAsStrings) {
            this.topMatchIds.add(Integer.valueOf(string));
        }
    }

    @Override
    void printInformation() {
        super.printInformation();
        System.out.println("\n");
        System.out.println("-- Specific information --");
        System.out.println("Sleeves: " + this.sleeves);
        System.out.println("Length: " + this.length);
        System.out.println("Neckline: " + this.neckline);
        System.out.println("Has buttons: " + this.hasButtons);
        System.out.println("Needs bottom: " + this.needsBottom);
        System.out.println("Needs match: " + this.needsMatch);
        System.out.println("Is dirty: " + this.isDirty());
    }

    void printShortInformation() {
        System.out.println("Top #" + super.idNumber + ": " + super.shortColor
                + " " + super.shortType + " from " + super.brand);
    }

    @Override
    void printInformationWithoutNames(String outFileName) throws IOException {
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
                outFileName, true)));

        super.printInformationWithoutNames(outFileName);
        out.println(this.sleeves);
        out.println(this.length);
        out.println(this.neckline);
        out.println(this.hasButtons);
        out.println(this.needsBottom);
        out.println(this.needsMatch);

        for (Integer id : this.topMatchIds) {
            out.println(id + ",");
        }

        out.close();
    }

    boolean isDirty() {
        boolean value = false;

        if (super.wears > 0) {
            value = true;
        }

        return value;
    }

    // / Setters for superclass
    void setBrand(String brand) {
        super.brand = brand;
    }

    void setColor(String color) {
        super.color = color;
    }

    void setSize(String size) {
        super.size = size;
    }

    void setMaterial(String material) {
        super.material = material;
    }

    void setShortType(String shortType) {
        super.shortType = shortType;
    }

    void setShortColor(String shortColor) {
        super.shortColor = shortColor;
    }

    void setIdNumber(int idNumber) {
        super.idNumber = idNumber;
    }

    void setMinimumTemperature(int minimumTemperature) {
        super.minimumTemperature = minimumTemperature;
    }

    void setWears(int wears) {
        super.wears = wears;
    }

    void setFormality(int formality) {
        super.formality = formality;
    }

    // / Setters for this class
    void setSleeves(String sleeves) {
        this.sleeves = sleeves;
    }

    void setLength(String length) {
        this.length = length;
    }

    void setNeckline(String neckline) {
        this.neckline = neckline;
    }

    void setHasButtons(boolean hasButtons) {
        this.hasButtons = hasButtons;
    }

    void setNeedsBottom(boolean needsBottom) {
        this.needsBottom = needsBottom;
    }

    void setNeedsMatch(boolean needsMatch) {
        this.needsMatch = needsMatch;
    }

}
